import { MICRO_SERVICE_ADMIN } from '~/constants/service-constant.ts'
import type { Page, Query } from '~/api/base/base-model.ts'
import type { PermissionReq, PermissionResp } from '~/api/setting/model/permission.ts'
import type { PermissionMenuReq } from '~/api/setting/model/permission-menu.ts'
import type { PermissionComponentReq } from '~/api/setting/model/permission-component.ts'
import type { PermissionApiReq } from '~/api/setting/model/permission-api.ts'

enum Api {
  QueryPermissionPage = '/webservice/permission/queryPermissionPage',
  QueryPermissionCheckedPageOfRoleId = '/webservice/permission/queryPermissionCheckedPageOfRoleId',
  QueryPermissionCheckedListOfRoleId = '/webservice/permission/queryPermissionCheckedListOfRoleId',
  CreatePermission = '/webservice/permission/createPermission',
  ModifyPermission = '/webservice/permission/modifyPermission',
  EnabledPermissionStateById = '/webservice/permission/enabledPermissionStateById',
  RemovePermissionById = '/webservice/permission/removePermissionById',
  BindPermissionMenuRelation = '/webservice/permission/bindPermissionMenuRelation',
  UnBindPermissionMenuRelation = '/webservice/permission/unBindPermissionMenuRelation',
  BindPermissionComponentRelation = '/webservice/permission/bindPermissionComponentRelation',
  UnBindPermissionComponentRelation = '/webservice/permission/unBindPermissionComponentRelation',
  BindPermissionApiRelation = '/webservice/permission/bindPermissionApiRelation',
  UnBindPermissionApiRelation = '/webservice/permission/unBindPermissionApiRelation',
}

/**
 * 获取权限分页列表
 * @param params 权限实体
 */
export function queryPermissionPageApi(params?: Query<PermissionReq>) {
  return usePost<Page<PermissionResp>, Query<PermissionReq>>(MICRO_SERVICE_ADMIN + Api.QueryPermissionPage, params)
}

/**
 * 获取根据角色ID标记权限选中列表
 * @param params 权限实体
 */
export function queryPermissionCheckedPageOfRoleId(params?: Query<PermissionReq>) {
  return usePost<Page<PermissionResp>, Query<PermissionReq>>(MICRO_SERVICE_ADMIN + Api.QueryPermissionCheckedPageOfRoleId, params)
}

/**
 * 获取根据角色ID标记权限选中列表
 * @param params 权限实体
 */
export function queryPermissionCheckedListRoleIdApi(params?: PermissionReq) {
  return usePost<PermissionResp, PermissionReq>(MICRO_SERVICE_ADMIN + Api.QueryPermissionCheckedListOfRoleId, params)
}

/**
 * 创建权限
 * @param params 权限实体
 */
export function createPermissionApi(params?: PermissionReq) {
  return usePost<PermissionResp, PermissionReq>(MICRO_SERVICE_ADMIN + Api.CreatePermission, params)
}

/**
 * 修改权限
 * @param params 权限实体
 */
export function modifyPermissionApi(params?: PermissionReq) {
  return usePost<PermissionResp, PermissionReq>(MICRO_SERVICE_ADMIN + Api.ModifyPermission, params)
}

/**
 * 开启或关闭权限状态
 * @param params 权限实体
 */
export function enabledPermissionStateByIdApi(params?: PermissionReq) {
  return useGet<PermissionResp, PermissionReq>(MICRO_SERVICE_ADMIN + Api.EnabledPermissionStateById, params)
}

/**
 * 删除权限
 * @param params 权限实体，使用其中ID
 */
export function removePermissionByIdApi(params?: PermissionReq) {
  return useGet<boolean>(MICRO_SERVICE_ADMIN + Api.RemovePermissionById, params)
}

/**
 * 绑定权限和菜单关系
 * @param params 权限实体
 */
export function bindPermissionMenuRelationApi(params?: PermissionMenuReq) {
  return usePost<PermissionResp, PermissionReq>(MICRO_SERVICE_ADMIN + Api.BindPermissionMenuRelation, params)
}

/**
 * 解除绑定权限和菜单关系
 * @param params 权限实体
 */
export function unBindPermissionMenuRelationApi(params?: PermissionMenuReq) {
  return usePost<PermissionResp, PermissionReq>(MICRO_SERVICE_ADMIN + Api.UnBindPermissionMenuRelation, params)
}

/**
 * 绑定权限和UI组件关系
 * @param params 权限实体
 */
export function bindPermissionComponentRelationApi(params?: PermissionComponentReq) {
  return usePost<PermissionResp, PermissionReq>(MICRO_SERVICE_ADMIN + Api.BindPermissionComponentRelation, params)
}

/**
 * 解除绑定权限和UI组件关系
 * @param params 权限实体
 */
export function unBindPermissionComponentRelationApi(params?: PermissionComponentReq) {
  return usePost<PermissionResp, PermissionReq>(MICRO_SERVICE_ADMIN + Api.UnBindPermissionComponentRelation, params)
}

/**
 * 绑定权限和接口关系
 * @param params 权限实体
 */
export function bindPermissionApiRelationApi(params?: PermissionApiReq) {
  return usePost<PermissionResp, PermissionReq>(MICRO_SERVICE_ADMIN + Api.BindPermissionApiRelation, params)
}

/**
 * 解除绑定权限和接口关系
 * @param params 权限实体
 */
export function unBindPermissionApiRelationApi(params?: PermissionApiReq) {
  return usePost<PermissionResp, PermissionReq>(MICRO_SERVICE_ADMIN + Api.UnBindPermissionApiRelation, params)
}
